
subdirs = 'mprpc'

def options(opt):
  opt.recurse(subdirs)

def configure(conf):
  conf.check_cxx(header_name = 'sys/socket.h net/if.h sys/ioctl.h', mandatory = True)
  conf.check_cxx(header_name = 'netinet/in.h arpa/inet.h', mandatory = True)
  conf.recurse(subdirs)

def build(bld):
  import Options
  src = 'exception.cpp util.cpp key_manager.cpp vector_util.cpp global_id_generator.cpp'
  if bld.env.HAVE_ZOOKEEPER_H:
    src += ' cached_zk.cpp zk.cpp membership.cpp cht.cpp lock_service.cpp'

  bld.shlib(
    source = src,
    target = 'jubacommon',
    includes = '.',
    use = 'PFICOMMON LIBGLOG ZOOKEEPER_MT jubacommon_mprpc'
    )

  test_src = [
    'exception_test.cpp',
    'key_manager_test.cpp',
    'util_test.cpp',
    'vector_util_test.cpp',
    ]

  if bld.env.HAVE_ZOOKEEPER_H:
    test_src += ['membership_test.cpp', 'cht_test.cpp']
    if bld.env.INTEGRATION_TEST:
      test_src += ['zk_test.cpp', 'cached_zk_test.cpp']
    
  def make_test(s):
    bld.program(
      features = 'gtest',
      source = s,
      target = s[0:s.rfind('.')],
      includes = '.',
      use = 'jubacommon'
      )
  map(make_test, test_src)

  bld.install_files('${PREFIX}/include/jubatus/common/', bld.path.ant_glob('*.hpp'))
  bld.recurse(subdirs)
